<!--
 * @Author: HZH
 * @Date: 2021-09-17 16:11:38
 * @LastEditors: HZH
 * @LastEditTime: 2021-09-23 17:04:52
 * @Description: 
-->
<template>
  <div class="List">
    <div class="bg">
      <Header></Header>
      <div class="wrapper">
        <div class="content">
          <div class="picture">
            <img src="../../public/2021zhongqiu.jpg" alt="" />
          </div>
          <div class="content_list">
            <div class="title">{{ category.name }}</div>
            <div class="dtlist">
              <div class="articleList" v-if="articleListData.total > 0">
                <div
                  class="art"
                  v-for="articleItem in articleListData.list"
                  :key="articleItem.id"
                  @click="ToArticle(articleItem)"
                >
                  <div class="logo">
                    <img :src="articleItem.cover" alt="" />
                  </div>
                  <div class="detailmes">
                    <div class="Arttitle" style="margin-bottom:10px">
                      {{ articleItem.title }}
                    </div>
                    <div class="pubTime" style="margin-bottom:6px">
                      发布时间：{{ articleItem.publishTime | fmtDate }}
                    </div>
                    <div class="readTime">
                      阅读次数：{{ articleItem.readTimes }}
                    </div>
                  </div>
                </div>
                <div class="page">
                  <el-pagination
                    @current-change="handleCurrentChange"
                    :current-page.sync="param.page"
                    :page-size="param.pageSize"
                    layout="total, prev, pager, next"
                    :total="articleListData.total"
                  >
                  </el-pagination>
                </div>
              </div>
              <div v-else class="nodata">暂无数据</div>
            </div>
          </div>
        </div>
      </div>
      <Footer></Footer>
    </div>
  </div>
</template>

<script>
import Header from "./components/Header.vue";
import Footer from "./components/Footer.vue";
import { get } from "../utils/request";
export default {
  components: {
    Header,
    Footer,
  },
  data() {
    return {
      category: {},
      param: {
        page: 1,
        pageSize: 4,
      },
      articleListData: {},
    };
  },
  methods: {
    getArticleData() {
      // console.log(this.param);
      this.param.categoryId = this.category.id;
      get("/index/article/pageQuery", this.param).then((res) => {
        // console.log(res);
        this.articleListData = res.data;
      });
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);

      // 使用当前页数与我们分页控制的参数进行赋值
      this.param.page = val;
      this.getArticleData();
    },
    ToArticle(articleItem){
      this.$router.push({
        path:'/Article',
        query:articleItem
      })
      
    }
  },
  watch: {
    "$route.query": {
      handler(query) {
        // // alert(JSON.stringify(query))
        this.category = query;
        // // 每次点击菜单栏将页数重置为1
        this.param.page = 1;
        this.getArticleData();
      },
      // 开启深度侦听
      deep: true,
    },
  },
  created() {
    this.category = this.$route.query;
    // console.log(this.category);
    this.getArticleData();
  },
};
</script>

<style lang="scss" scoped>
.List {
  .bg {
    background: url("../../public/新建画布1.png") no-repeat;
    // width: 100%;
    background-size: 100% 100%;
    // height: 3000px;
    .wrapper {
      .picture {
        img {
          width: 1240px;
          height: 250px;
        }
        margin-top: 20px;
      }
      .content_list {
        margin-top: 20px;
        background-color: #f5f7ff;
        border-radius: 5px;
        // height: 460px;
        min-height: 460px;
        display: flex;
        justify-content: space-between;
        .title {
          flex: 1;
          font-size: 24px;
          font-weight: bold;
          color: #fff;
          background-color: #31466a;
          padding-left: 150px;
          padding-top: 20px;
        }
        .dtlist {
          flex: 3;
          padding: 20px;
          .articleList{
            .art{
              display: flex;
              background-color: #fff;
              margin-bottom: 20px;
              border-radius: 5px;
              height: 100px;
              .logo{
                flex: 1;
                img{
                  width: 200px;
                  height: 100px;
                }
              }
              .detailmes{
                flex: 2;
                padding: 15px;
                .Arttitle{
                  cursor: pointer;
                  overflow: hidden;
                  white-space: nowrap;
                  // // text-overflow: ellipsis;
                  text-overflow: ellipsis;
                  font-size: 18px;
                  font-weight: bold;
                }
              }
            }
            
          }
        }
      }
    }
  }
}
</style>